//
//  ViewController.m
//  AddressBook
//
//  Created by 张洪毓 on 15/11/26.
//  Copyright © 2015年 张洪毓. All rights reserved.
//

#import "ViewController.h"
#import <AddressBookUI/AddressBookUI.h>
@interface ViewController () <ABPeoplePickerNavigationControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    ABPeoplePickerNavigationController *nav = [[ABPeoplePickerNavigationController alloc] init];
    nav.peoplePickerDelegate = self;
    [self presentViewController:nav animated:YES completion:nil];
}

-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person{

    CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
    CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
    NSString *first = (__bridge_transfer  NSString *)(firstName);
    NSString *last = (__bridge_transfer  NSString *)lastName;
    NSLog(@"%@-----%@",first,last);
//    if (firstName) {
//        CFRelease(firstName);
//    }
//    if (lastName) {
//        CFRelease(lastName);
//    }
    
    ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex count = ABMultiValueGetCount(phones);
    for (CFIndex i = 0; i < count; i++) {
        CFStringRef phone = ABMultiValueCopyValueAtIndex(phones, i);
        NSString *phontStr = (__bridge_transfer  NSString *)phone;
        NSLog(@"---->>>>>>%@",phontStr);
//        CFRelease(phone);
    }
    CFRelease(phones);
}


@end
